package org.oschina.api.blog.recommend.controller;

import org.oschina.api.blog.recommend.service.BlogRecommendService;
import org.oschina.api.blog.recommend.vo.BlogRecommendVo;
import org.oschina.bean.Pager;
import org.oschina.bean.Result;
import org.oschina.config.Config;
import org.oschina.handler.validator.annotation.Validate;
import org.oschina.handler.validator.annotation.ValidateField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value=Config.API_PATH+"/blog/recommend")
public class BlogRecommendController {

	@Autowired
	private BlogRecommendService blogRecommendService;
	
	/**
	 * 自荐
	 * @param id
	 * @return
	 */
	@Validate
	@RequestMapping(value="/create",method=RequestMethod.POST)
	public Result recommend
	(
		@Validate(validateField=@ValidateField(validateValue=true,min=1)) Integer id
	)
	{
		return blogRecommendService.recommend(id);
	}
	
	/**
	 * 返回
	 * @param pn
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public Pager<BlogRecommendVo> findVo(Integer pn)
	{
		if(pn==null || pn<=0)
			pn=1;
		
		return blogRecommendService.findVo(pn);
	}
	
	/**
	 * 通过
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/pass/{id}",method=RequestMethod.POST)
	public Result pass
	(
		@PathVariable @Validate(validateField=@ValidateField(validateValue=true,min=1)) Integer id
	)
	{
		return blogRecommendService.pass(id);
	}
	
	/**
	 * 拒绝
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/refuse/{id}",method=RequestMethod.POST)
	public Result refuse
	(
		@PathVariable @Validate(validateField=@ValidateField(validateValue=true,min=1)) Integer id
	)
	{
		return blogRecommendService.refuse(id);
	}
}